$(function() {
    var $t, leftX, newWidth;

    $('.menu ul').append('<div class="underLine"></div>');
    var $underLine = $('.underLine');

    $underLine.width($(".curr").width()).css('left', $('.curr a').position().left).data('rightLeft', $underLine.position().left).data('rightWidth', $underLine.width());

    $('.menu ul li').find('a').hover(function() {
        $t = $(this);
        leftX = $t.position().left;
        newWidth = $t.parent().width();

        $underLine.stop().animate({
            left: leftX,
            width: newWidth
        },300);
    }, function() {
        $underLine.stop().animate({
            left: $underLine.data('rightLeft'),
            width: $underLine.data('rightWidth')
        },300)
    });

    var ie6 = /msie 6/i.test(navigator.userAgent),
        div = $('.fixed_cont'),
        nav = $('.fixed_nav'),
        st,sb;
    div.attr('divTop', div.offset().top); //存储原来的距离顶部的距离
    nav.attr('navTop',nav.offset().top);
    $(window).scroll(function () {
        st = $(window).scrollTop();
        sb = $(document).height() - $(window).scrollTop() - $(".fixed_cont").height();
        if ( st >= parseInt(div.attr('divTop'))) {
            if( sb > 226){
                if (ie6) {
                    div.css({ position: 'absolute', top: st-115 });
                } else if (div.css('position') != 'fixed') div.css({ 'position': 'fixed', top: '5px'});
            } else if (div.css('position') != 'static') div.css({ 'position': 'static' });
        } else if (div.css('position') != 'static') div.css({ 'position': 'static' });


        if ( st >= parseInt(nav.attr('navTop'))) {
            if (ie6) {
                nav.css({ position: 'absolute', top: st-120 });
            } else if (nav.css('position') != 'fixed') nav.css({ 'position':'fixed',top: 0});
        } else if (nav.css('position') != 'static') nav.css({ 'position': 'static' });

    });

})